﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using Infragistics.Win.UltraWinCalcManager;
using Infragistics.Win.CalcEngine;
using WeifenLuo.WinFormsUI.Docking;
using GoldPrinter;
using cfg = System.Configuration;

namespace BYManageInfoSystem
{
    public partial class Frm_ContractBatchPrint : DockContent
    {
        CheckBoxOnHeader_CreationFilter aCheckBoxOnHeader_CreationFilter = new CheckBoxOnHeader_CreationFilter();
        private DGBY.BLL.PaidanRegisterTab m_bllPaidanRegisterTab = new DGBY.BLL.PaidanRegisterTab();
        private DGBY.BLL.BGPackingTab m_bllBGPackingTab = new DGBY.BLL.BGPackingTab();
        private DGBY.BLL.BGCKHTTab m_bllBGCKHTTab = new DGBY.BLL.BGCKHTTab();
        private DGBY.BLL.BYCompanyTab bllBYCompanyTab = new DGBY.BLL.BYCompanyTab();
        private DGBY.BLL.BiZhiTab m_bllBiZhiTab = new DGBY.BLL.BiZhiTab();
        private DGBY.BLL.SHCompTab m_bllSHCompTab = new DGBY.BLL.SHCompTab();
        private DGBY.BLL.ZYHarborTab m_bllZYHarborTab = new DGBY.BLL.ZYHarborTab();
        private DGBY.BLL.BGPackGoodsMXTab m_bllBGPackGoodsMXTab = new DGBY.BLL.BGPackGoodsMXTab();
        public static DGBY.BLL.TaoDaPrinterNameTab m_bllTaoDaPrinterNameTab = new DGBY.BLL.TaoDaPrinterNameTab();
        protected string templetFilePath = cfg.ConfigurationSettings.AppSettings["TempletFilePath"];
        private bool m_bLastModifiedCellIsSelect = false;
        private int m_nSelectlIndex = -1;

        Dictionary<int, int> m_dicSelectID2RowNo = new Dictionary<int, int>();
        public Frm_ContractBatchPrint()
        {
            InitializeComponent();
        }

        private void Frm_ContractBatchPrint_Load(object sender, EventArgs e)
        {
            InitComBox();
            ClassUltraGridCommonSet.InitUltraWinGridSetting(this.ultraGrid1);

            this.ultraGrid1.CreationFilter = aCheckBoxOnHeader_CreationFilter;
            aCheckBoxOnHeader_CreationFilter.SetParam(m_dicSelectID2RowNo, this.ultraGrid1);
        }

        private void InitComBox()
        {
            this.comboBoxShowWay.Items.AddRange(new object[] { "最近半年记录", "全部记录" });
            this.comboBoxShowWay.SelectedIndex = 0;
        }

        private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e)
        {
            ultraGrid1.DisplayLayout.Override.RowSizing = RowSizing.AutoFree;
            if (this.checkBox1.Checked == true)
                ultraGrid1_InitializeRowFilter(e);
            else
                ClassUltraGridCommonSet.ultraGrid1_InitializeRowFilter(e);

            InitColumnWidth();

            e.Layout.Bands[0].Columns["全选"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.CheckBox;
            for (int i = 1; i < this.ultraGrid1.DisplayLayout.Bands[0].Columns.Count; i++)
            {
                e.Layout.Bands[0].Columns[i].CellMultiLine = DefaultableBoolean.True;
            }

            foreach (UltraGridColumn column2 in ultraGrid1.DisplayLayout.Bands[0].Columns)
            {
                 string str = column2.Header.Caption;
                 if (str != "全选")
                 {
                     column2.CellActivation = Activation.ActivateOnly;
                 }
            }
        }

        private void InitColumnWidth()
        {
            ultraGrid1.DisplayLayout.Bands[0].Columns["全选"].Width = 40;
            ultraGrid1.DisplayLayout.Bands[0].Columns["业务员"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["申报年月"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["公司"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["部门"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["订单号"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["工厂简称"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["合同编号"].Width = 75;
            ultraGrid1.DisplayLayout.Bands[0].Columns["柜号"].Width = 90;
            ultraGrid1.DisplayLayout.Bands[0].Columns["申报日期"].Width = 95;
            ultraGrid1.DisplayLayout.Bands[0].Columns["报关金额"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["币制"].Width = 45;
            ultraGrid1.DisplayLayout.Bands[0].Columns["目的国家"].Width = 75;
            ultraGrid1.DisplayLayout.Bands[0].Columns["柜数"].Width = 40;
            ultraGrid1.DisplayLayout.Bands[0].Columns["总毛重"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["总净重"].Width = 60;
        }

        public static void ultraGrid1_InitializeRowFilter(Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
        {
            //ultraGrid1.DisplayLayout.Override.RowSizing = RowSizing.AutoFree;
            //foreach (UltraGridColumn ugc in ultraGrid1.DisplayLayout.Bands[0].Columns)
            //    ugc.PerformAutoResize();
            // FILTER ROW FUNCTIONALITY RELATED ULTRAGRID SETTINGS
            //e.Layout.Override.RowFilterAction = RowFilterAction.DisableFilteredOutRows;
            // ----------------------------------------------------------------------------------
            // Enable the the filter row user interface by setting the FilterUIType to FilterRow.
            e.Layout.Override.FilterUIType = FilterUIType.FilterRow;
            //e.Layout.Override.RowFilterMode = RowFilterMode.AllRowsInBand;
            // FilterEvaluationTrigger specifies when UltraGrid applies the filter criteria typed 
            // into a filter row. Default is OnCellValueChange which will cause the UltraGrid to
            // re-filter the data as soon as the user modifies the value of a filter cell.
            e.Layout.Override.FilterEvaluationTrigger = FilterEvaluationTrigger.OnCellValueChange;
            //e.Layout.Override.RowFilterMode = RowFilterMode.AllRowsInBand;
            // By default the UltraGrid selects the type of the filter operand editor based on
            // the column's DataType. For DateTime and boolean columns it uses the column's editors.
            // For other column types it uses the Combo. You can explicitly specify the operand
            // editor style by setting the FilterOperandStyle on the override or the individual
            // columns.

            e.Layout.Override.FilterOperandStyle = FilterOperandStyle.DropDownList;

            // By default UltraGrid displays user interface for selecting the filter operator. 
            // You can set the FilterOperatorLocation to hide this user interface. This
            // property is available on column as well so it can be controlled on a per column
            // basis. Default is WithOperand. This property is exposed off the column as well.
            e.Layout.Override.FilterOperatorLocation = FilterOperatorLocation.WithOperand;

            // By default the UltraGrid uses StartsWith as the filter operator. You use
            // the FilterOperatorDefaultValue property to specify a different filter operator
            // to use. This is the default or the initial filter operator value of the cells
            // in filter row. If filter operator user interface is enabled (FilterOperatorLocation
            // is not set to None) then that ui will be initialized to the value of this
            // property. The user can then change the operator as he/she chooses via the operator
            // drop down.
            e.Layout.Override.FilterOperatorDefaultValue = FilterOperatorDefaultValue.Contains;

            // FilterOperatorDropDownItems property can be used to control the options provided
            // to the user for selecting the filter operator. By default UltraGrid bases 
            // what operator options to provide on the column's data type. This property is
            // avaibale on the column as well.
            //e.Layout.Override.FilterOperatorDropDownItems = FilterOperatorDropDownItems.All;

            // By default UltraGrid displays a clear button in each cell of the filter row
            // as well as in the row selector of the filter row. When the user clicks this
            // button the associated filter criteria is cleared. You can use the 
            // FilterClearButtonLocation property to control if and where the filter clear
            // buttons are displayed.
            e.Layout.Override.FilterClearButtonLocation = FilterClearButtonLocation.RowAndCell;

            // Appearance of the filter row can be controlled using the FilterRowAppearance proeprty.
            e.Layout.Override.FilterRowAppearance.BackColor = Color.LightYellow;

            // You can use the FilterRowPrompt to display a prompt in the filter row. By default
            // UltraGrid does not display any prompt in the filter row.
            e.Layout.Override.FilterRowPrompt = "Click here to filter data...";

            // You can use the FilterRowPromptAppearance to change the appearance of the prompt.
            // By default the prompt is transparent and uses the same fore color as the filter row.
            // You can make it non-transparent by setting the appearance' BackColorAlpha property 
            // or by setting the BackColor to a desired value.
            e.Layout.Override.FilterRowPromptAppearance.BackColorAlpha = Alpha.Opaque;

            // By default the prompt is spread across multiple cells if it's bigger than the
            // first cell. You can confine the prompt to a particular cell by setting the
            // SpecialRowPromptField property off the band to the key of a column.
            //e.Layout.Bands[0].SpecialRowPromptField = e.Layout.Bands[0].Columns[0].Key;

            // Display a separator between the filter row other rows. SpecialRowSeparator property 
            // can be used to display separators between various 'special' rows, including for the
            // filter row. This property is a flagged enum property so it can take multiple values.
            e.Layout.Override.SpecialRowSeparator = SpecialRowSeparator.FilterRow;

            // You can control the appearance of the separator using the SpecialRowSeparatorAppearance
            // property.
            e.Layout.Override.SpecialRowSeparatorAppearance.BackColor = Color.FromArgb(233, 242, 199);
        }

        private void buttonShowAll_Click(object sender, EventArgs e)
        {
            ShowAllRecordInDataGridView();
        }

        private void ShowAllRecord(string strWhere)
        {
            DataSet ds = m_bllPaidanRegisterTab.ShowContractBatchPrint(strWhere);
            ultraGrid1.DataSource = null;

            ultraGrid1.DataSource = ds.Tables[0];
            ultraGrid1.DisplayLayout.Bands[0].Columns["PaidanRegisterTabID"].Hidden = true;
        }

        private void ShowAllRecordSort(string strWhere)
        {
            DataSet ds = m_bllPaidanRegisterTab.ShowContractBatchPrintSort(strWhere);
            ultraGrid1.DataSource = null;

            ultraGrid1.DataSource = ds.Tables[0];
            ultraGrid1.DisplayLayout.Bands[0].Columns["PaidanRegisterTabID"].Hidden = true;
        }

        private void ShowAllRecordInDataGridView()
        {
            string strTemp = this.comboBoxShowWay.Text;
            if (strTemp == "全部记录")
                ShowAllRecord("");
            else
            {
                DateTime dtNow = System.DateTime.Now.Date.AddDays(-180);
                ShowAllRecord("case when year(HxdNoTab.SBDate) = 1900 then getdate() else HxdNoTab.SBDate end >= '" + dtNow + "'");
            }
        }

        /*
This CreationFilter class will create a CheckBoxUIElement in each Column Header
whose DataType is boolean. It will fire the HeaderCheckBoxClicked event 
whenever the CheckBox is clicked.
Note that in order to maintain the CheckState, this CreationFilter uses the 
Tag proprty of the Header. So if the program uses the tag for something else
this will not work. 
*/
        // Implements the CreationFilter interface		
        public class CheckBoxOnHeader_CreationFilter : IUIElementCreationFilter
        {
            // This event will fire when the CheckBox is clicked. 
            public delegate void HeaderCheckBoxClickedHandler(object sender, HeaderCheckBoxEventArgs e);
            public event HeaderCheckBoxClickedHandler _CLICKED;
            public Dictionary<int, int> m_dicSelectID2RowNo = new Dictionary<int, int>();
            public Infragistics.Win.UltraWinGrid.UltraGrid m_ultraGrid1;
            public void SetParam(Dictionary<int, int> dicSelectID2RowNo, Infragistics.Win.UltraWinGrid.UltraGrid ultraGrid1)
            {
                m_dicSelectID2RowNo = dicSelectID2RowNo;
                m_ultraGrid1 = ultraGrid1;

            }
            public CheckBoxOnHeader_CreationFilter()
            {
                _CLICKED += new HeaderCheckBoxClickedHandler(aCheckBoxOnHeader_CreationFilter_HeaderCheckBoxClicked);
            }

            private void aCheckBoxOnHeader_CreationFilter_HeaderCheckBoxClicked(object sender, CheckBoxOnHeader_CreationFilter.HeaderCheckBoxEventArgs e)
            {
                // Check to see if the column is of type boolean.  If it is, set all the cells in that column to
                // whatever value the header checkbox is.
                if (e.Header.Column.Header.Caption == "全选")
                {
                    //foreach (UltraGridRow aRow in e.Rows)
                    //{
                    //    aRow.Cells[e.Header.Column.Index].Value = (e.CurrentCheckState == CheckState.Checked);
                    //}
                    if (e.CurrentCheckState == CheckState.Checked)
                    {
                        Infragistics.Win.UltraWinGrid.UltraGridRow[] ugr = m_ultraGrid1.Rows.GetFilteredInNonGroupByRows();
                        if (ugr.Length <= 0)
                        {
                            return;
                        }

                        for (int i = 0; i < ugr.Length; i++)
                        {
                            int iIndex = ugr[i].Index;
                            UltraGridRow CurrentUGR = m_ultraGrid1.Rows[iIndex];
                            int nSelectFinRecvMoneyDetailTab_NewID = Convert.ToInt32(CurrentUGR.Cells[0].Value.ToString(), 10);

                            CurrentUGR.Cells["全选"].Value = 1;
                            if (!m_dicSelectID2RowNo.Keys.Contains(nSelectFinRecvMoneyDetailTab_NewID))
                                m_dicSelectID2RowNo.Add(nSelectFinRecvMoneyDetailTab_NewID, iIndex);

                            //else
                            //{
                            //    CurrentUGR.Cells["全选"].Value = 0;
                            //    

                            //}
                        }
                    }
                    else
                    {
                        foreach (int nID in m_dicSelectID2RowNo.Keys)
                        {
                            UltraGridRow CurrentUGR = m_ultraGrid1.Rows[m_dicSelectID2RowNo[nID]];
                            CurrentUGR.Cells["全选"].Value = 0;
                        }

                        m_dicSelectID2RowNo.Clear();
                    }
                }
            }

            // EventArgs used for the HeaderCheckBoxClicked event. This event has to pass in the CheckState and the ColumnHeader
            #region HeaderCheckBoxEventArgs
            public class HeaderCheckBoxEventArgs : EventArgs
            {
                private Infragistics.Win.UltraWinGrid.ColumnHeader mvarColumnHeader;
                private CheckState mvarCheckState;
                private RowsCollection mvarRowsCollection;

                public HeaderCheckBoxEventArgs(Infragistics.Win.UltraWinGrid.ColumnHeader hdrColumnHeader, CheckState chkCheckState, RowsCollection Rows)
                {
                    mvarColumnHeader = hdrColumnHeader;
                    mvarCheckState = chkCheckState;
                    mvarRowsCollection = Rows;
                }

                // Expose the rows collection for the specific row island that the header belongs to
                public RowsCollection Rows
                {
                    get
                    {
                        return mvarRowsCollection;
                    }
                }

                public Infragistics.Win.UltraWinGrid.ColumnHeader Header
                {
                    get
                    {
                        return mvarColumnHeader;
                    }
                }

                public CheckState CurrentCheckState
                {
                    get
                    {
                        return mvarCheckState;
                    }
                    set
                    {
                        mvarCheckState = value;
                    }
                }
            }
            #endregion

            private void aCheckBoxUIElement_ElementClick(Object sender, Infragistics.Win.UIElementEventArgs e)
            {
                // Get the CheckBoxUIElement that was clicked
                CheckBoxUIElement aCheckBoxUIElement = (CheckBoxUIElement)e.Element;

                // Get the Header associated with this particular element
                Infragistics.Win.UltraWinGrid.ColumnHeader aColumnHeader = (Infragistics.Win.UltraWinGrid.ColumnHeader)aCheckBoxUIElement.GetAncestor(typeof(HeaderUIElement)).GetContext(typeof(Infragistics.Win.UltraWinGrid.ColumnHeader));

                // Set the Tag on the Header to the new CheckState
                aColumnHeader.Tag = aCheckBoxUIElement.CheckState;

                // So that we can apply various changes only to the relevant Rows collection that the header belongs to
                HeaderUIElement aHeaderUIElement = aCheckBoxUIElement.GetAncestor(typeof(HeaderUIElement)) as HeaderUIElement;
                RowsCollection hRows = aHeaderUIElement.GetContext(typeof(RowsCollection)) as RowsCollection;

                // Raise an event so the programmer can do something when the CheckState changes
                if (_CLICKED != null)
                    _CLICKED(this, new HeaderCheckBoxEventArgs(aColumnHeader, aCheckBoxUIElement.CheckState, hRows));
            }

            public bool BeforeCreateChildElements(Infragistics.Win.UIElement parent)  // Implements Infragistics.Win.IUIElementCreationFilter.BeforeCreateChildElements
            {
                // Don't need to do anything here
                return false;
            }

            public void AfterCreateChildElements(Infragistics.Win.UIElement parent) // Implements Infragistics.Win.IUIElementCreationFilter.AfterCreateChildElements
            {
                // Check for the HeaderUIElement
                if (parent is HeaderUIElement)
                {
                    // Get the HeaderBase object from the HeaderUIElement
                    Infragistics.Win.UltraWinGrid.HeaderBase aHeader = ((HeaderUIElement)parent).Header;

                    // Only put the checkbox into headers whose DataType is boolean
                    if (aHeader.Column.Header.Caption == "全选")
                    {
                        TextUIElement aTextUIElement;
                        CheckBoxUIElement aCheckBoxUIElement = (CheckBoxUIElement)parent.GetDescendant(typeof(CheckBoxUIElement));

                        // Since the grid sometimes re-uses UIElements, we need to check to make sure 
                        // the header does not already have a CheckBoxUIElement attached to it.
                        // If it does, we just get a reference to the existing CheckBoxUIElement,
                        // and reset its properties.
                        if (aCheckBoxUIElement == null)
                        {
                            //Create a New CheckBoxUIElement
                            aCheckBoxUIElement = new CheckBoxUIElement(parent);
                        }

                        // Get the TextUIElement - this is where the text for the 
                        // Header is displayed. We need this so we can push it to the right
                        // in order to make room for the CheckBox
                        aTextUIElement = (TextUIElement)parent.GetDescendant(typeof(TextUIElement));

                        // Sanity check
                        if (aTextUIElement == null)
                            return;

                        // Get the Header and see if the Tag has been set. If the Tag is 
                        // set, we will assume it's the stored CheckState. This has to be
                        // done in order to maintain the CheckState when the grid repaints and
                        // UIElement are destroyed and recreated. 
                        Infragistics.Win.UltraWinGrid.ColumnHeader aColumnHeader =
                            (Infragistics.Win.UltraWinGrid.ColumnHeader)aCheckBoxUIElement.GetAncestor(typeof(HeaderUIElement))
                            .GetContext(typeof(Infragistics.Win.UltraWinGrid.ColumnHeader));

                        if (aColumnHeader.Tag == null)
                            //If the tag was nothing, this is probably the first time this 
                            //Header is being displayed, so default to Indeterminate
                            aColumnHeader.Tag = CheckState.Indeterminate;
                        else
                            aCheckBoxUIElement.CheckState = (CheckState)aColumnHeader.Tag;

                        // Hook the ElementClick of the CheckBoxUIElement
                        aCheckBoxUIElement.ElementClick += new UIElementEventHandler(aCheckBoxUIElement_ElementClick);

                        // Add the CheckBoxUIElement to the HeaderUIElement
                        parent.ChildElements.Add(aCheckBoxUIElement);

                        // Position the CheckBoxUIElement. The number 3 here is used for 3
                        // pixels of padding between the CheckBox and the edge of the Header.
                        // The CheckBox is shifted down slightly so it is centered in the header.
                        aCheckBoxUIElement.Rect = new Rectangle(parent.Rect.X + 3, parent.Rect.Y + ((parent.Rect.Height - aCheckBoxUIElement.CheckSize.Height) / 2), aCheckBoxUIElement.CheckSize.Width, aCheckBoxUIElement.CheckSize.Height);

                        // Push the TextUIElement to the right a little to make 
                        // room for the CheckBox. 3 pixels of padding are used again. 
                        aTextUIElement.Rect = new Rectangle(aCheckBoxUIElement.Rect.Right + 3, aTextUIElement.Rect.Y, parent.Rect.Width - (aCheckBoxUIElement.Rect.Right - parent.Rect.X), aTextUIElement.Rect.Height);
                    }
                    else
                    {
                        // If the column is not a boolean column, we do not want to have a checkbox in it
                        // Since UIElements can be reused by the grid, there is a chance that one of the
                        // HeaderUIElements that we added a checkbox to for a boolean column header
                        // will be reused in a column that is not boolean.  In this case, we must remove
                        // the checkbox so that it will not appear in an inappropriate column header.
                        CheckBoxUIElement aCheckBoxUIElement = (CheckBoxUIElement)parent.GetDescendant(typeof(CheckBoxUIElement));

                        if (aCheckBoxUIElement != null)
                        {
                            parent.ChildElements.Remove(aCheckBoxUIElement);
                            aCheckBoxUIElement.Dispose();
                        }
                    }
                }
            }
        }

        private void buttonPrint_Click(object sender, EventArgs e)
        {
            if (m_dicSelectID2RowNo.Count == 0)
            {
                MessageBox.Show("未勾选记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            foreach (int nID in m_dicSelectID2RowNo.Keys)
            {
                UltraGridRow SelectUGR = ultraGrid1.Rows[m_dicSelectID2RowNo[nID]];
                int nPaidanID = Convert.ToInt32(SelectUGR.Cells["PaidanRegisterTabID"].Value.ToString());

                DGBY.Model.PaidanRegisterTab modelPaidanTab = m_bllPaidanRegisterTab.GetModel(nPaidanID);
                if (modelPaidanTab == null)
                    continue;

                if (!CheckBGPackingSheetGuiXing(nPaidanID))
                {
                    MessageBox.Show(modelPaidanTab.ContractCode + "号装箱单柜型未设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (!CheckBGPackingSheetBGH(nPaidanID))
                {
                    MessageBox.Show(modelPaidanTab.ContractCode + "号装箱单报关行未设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                DataTable dt = null;
                DataSet m_ds = m_bllBGCKHTTab.ShowAllCKHTMX(modelPaidanTab.ContractCode);
                if (m_ds.Tables.Count > 0 && m_ds.Tables[0].Rows.Count > 0)
                {
                    dt = m_ds.Tables[0];
                    //  if (Frm_Main.m_bCompleteVer == true)
                    {
                        dt.Columns.Remove("单价");
                        dt.Columns.Remove("金额");
                        dt.Columns["打折单价"].ColumnName = "单价";
                        dt.Columns["打折金额"].ColumnName = "金额";
                    }
                    //else
                    //{
                    //    dt.Columns.Remove("打折单价");
                    //    dt.Columns.Remove("打折金额");
                    //}
                }

                DataSet dsContract = m_bllBGCKHTTab.ShowOneOutContractRecFromCK("BGCKHTTab.PaidanRegisterTabID = '" + nPaidanID + "'");
                if (dsContract.Tables.Count == 0)
                    continue;

                DataTable dt1 = dsContract.Tables[0];
                DataSet DsBYCompInfo = bllBYCompanyTab.GetList("CompanyName = '" + dt1.Rows[0]["卖方"].ToString() + "'");
                DataSet DsSHCompInfo = m_bllSHCompTab.GetList("CompanyName = '" + dt1.Rows[0]["买方"].ToString() + "'");
                string strBizhi = dt.Rows[0]["币制"].ToString();
                m_ds = m_bllBiZhiTab.GetList("BiZhiName = '" + strBizhi + "'");
                DataTable dtBizhi = m_ds.Tables[0];
                string strPort = dt1.Rows[0]["装运口岸"].ToString();
                m_ds = m_bllZYHarborTab.GetList("ZYHarborName = '" + strPort + "'");
                DataTable dtPort = m_ds.Tables[0];
                if (dt1 != null)
                {
                    if (dt1.Rows.Count > 1)
                    {
                        MessageBox.Show("请选择不多于一条出口合同记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("出口合同记录不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        string templetFile = templetFilePath + "报关_出口合同.xlt";
                        string outFile = "";
                        ExcelBase eB = new ExcelBase(templetFile, outFile);

                        try
                        {
                            eB.SeaGateConstract_DataTableToExcelAndPrint(dt, dt1, DsBYCompInfo.Tables[0]
                                , DsSHCompInfo.Tables[0], 19, 16, 1, "页", 1, dtBizhi, dtPort);
                        }
                        catch (System.Exception ex)
                        {

                        }

                        eB.Close();
                    }
                }
                else
                {
                    MessageBox.Show("出口合同明细不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }

        private bool CheckBGPackingSheetGuiXing(int nPaidanID)
        {
            DataSet ds = m_bllBGPackingTab.GetList("PaidanRegisterTabID = '" + nPaidanID + "'"
                + " and GuiXingTabID = 6");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        private bool CheckBGPackingSheetBGH(int nPaidanID)
        {
            DataSet ds = m_bllBGPackingTab.GetList("PaidanRegisterTabID = '" + nPaidanID + "'"
                + " and BGHDataTabID = 33");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        private void ultraGrid1_CellChange(object sender, CellEventArgs e)
        {
            if (!StringComparer.Ordinal.Equals(e.Cell.Column.Key, @"全选"))
            {
                m_bLastModifiedCellIsSelect = false;
                return;
            }
            m_bLastModifiedCellIsSelect = true;
            int iIndex = e.Cell.Row.Index;
            if (iIndex < 0)
                return;
            UltraGridRow CurrentUGR = ultraGrid1.Rows[iIndex];


            int nSelectFinRecvMoneyDetailTab_NewID = Convert.ToInt32(CurrentUGR.Cells[0].Value.ToString(), 10);

            if (e.Cell.Text == "1")
            {
                if (!m_dicSelectID2RowNo.Keys.Contains(nSelectFinRecvMoneyDetailTab_NewID))
                    m_dicSelectID2RowNo.Add(nSelectFinRecvMoneyDetailTab_NewID, iIndex);
            }
            else
            {
                if (m_dicSelectID2RowNo.Keys.Contains(nSelectFinRecvMoneyDetailTab_NewID))
                    m_dicSelectID2RowNo.Remove(nSelectFinRecvMoneyDetailTab_NewID);
            }
        }

        private void ultraGrid1_AfterCellActivate(object sender, EventArgs e)
        {
            int iIndex = this.ultraGrid1.ActiveCell.Row.Index;
            if (iIndex < 0)
                return;
            m_nSelectlIndex = ultraGrid1.ActiveRow.Index;
        }

        private void buttonPrintPreview_Click(object sender, EventArgs e)
        {
            if (m_nSelectlIndex < 0)
            {
                MessageBox.Show("请选择一行记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }


            UltraGridRow SelectUGR = ultraGrid1.Rows[m_nSelectlIndex];
            int nPaidanID = Convert.ToInt32(SelectUGR.Cells["PaidanRegisterTabID"].Value.ToString());

            if (!CheckBGPackingSheetGuiXing(nPaidanID))
            {
                MessageBox.Show("该合同号装箱单柜型未设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (!CheckBGPackingSheetBGH(nPaidanID))
            {
                MessageBox.Show("该合同号装箱单报关行未设置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            DGBY.Model.PaidanRegisterTab modelPaidanTab = m_bllPaidanRegisterTab.GetModel(nPaidanID);
            if (modelPaidanTab == null)
                return;

            DataTable dt = null;
            DataSet dsCKHTMX = m_bllBGCKHTTab.ShowAllCKHTMX(modelPaidanTab.ContractCode);
            if (dsCKHTMX.Tables.Count > 0 && dsCKHTMX.Tables[0].Rows.Count > 0)
            {
                dt = dsCKHTMX.Tables[0];
                //   if (Frm_Main.m_bCompleteVer == true)
                {
                    dt.Columns.Remove("单价");
                    dt.Columns.Remove("金额");
                    dt.Columns["打折单价"].ColumnName = "单价";
                    dt.Columns["打折金额"].ColumnName = "金额";
                }
                //else
                //{
                //    dt.Columns.Remove("打折单价");
                //    dt.Columns.Remove("打折金额");
                //}
            }

            DataSet dsContract = m_bllBGCKHTTab.ShowOneOutContractRecFromCK("BGCKHTTab.PaidanRegisterTabID = '" + nPaidanID + "'");
            if (dsContract.Tables.Count == 0)
                return;

            DataTable dt1 = dsContract.Tables[0];

            DataSet DsBYCompInfo = bllBYCompanyTab.GetList("CompanyName = '" + dt1.Rows[0]["卖方"].ToString() + "'");
            DataSet DsSHCompInfo = m_bllSHCompTab.GetList("CompanyName = '" + dt1.Rows[0]["买方"].ToString() + "'");
            string strBizhi = dt.Rows[0]["币制"].ToString();
            dsCKHTMX = m_bllBiZhiTab.GetList("BiZhiName = '" + strBizhi + "'");
            DataTable dtBizhi = dsCKHTMX.Tables[0];

            string strPort = dt1.Rows[0]["装运口岸"].ToString();
            dsCKHTMX = m_bllZYHarborTab.GetList("ZYHarborName = '" + strPort + "'");
            DataTable dtPort = dsCKHTMX.Tables[0];
            if (dt1 != null)
            {
                if (dt1.Rows.Count > 1)
                {
                    MessageBox.Show("请选择不多于一条出口合同记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            else
            {
                MessageBox.Show("出口合同记录不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    string templetFile = templetFilePath + "报关_出口合同.xlt";
                    string outFile = "";
                    ExcelBase eB = new ExcelBase(templetFile, outFile);

                    try
                    {
                        eB.SeaGateConstract_DataTableToExcelAndPrintPreview(dt, dt1
                            , DsBYCompInfo.Tables[0], DsSHCompInfo.Tables[0], 20, 16, 1, "页", 1, dtBizhi, dtPort);
                    }
                    catch (System.Exception ex)
                    {

                    }
                }
            }
            else
            {
                MessageBox.Show("出口合同明细不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void buttonSendGoodsPrint_Click(object sender, EventArgs e)
        {
            if (m_dicSelectID2RowNo.Count == 0)
            {
                MessageBox.Show("未勾选记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            foreach (int nID in m_dicSelectID2RowNo.Keys)
            {
                UltraGridRow SelectUGR = ultraGrid1.Rows[m_dicSelectID2RowNo[nID]];
                int nPaidanID = Convert.ToInt32(SelectUGR.Cells["PaidanRegisterTabID"].Value.ToString());

                DGBY.Model.PaidanRegisterTab modelPaidanTab = m_bllPaidanRegisterTab.GetModel(nPaidanID);
                if (modelPaidanTab == null)
                    return;

                int nSelectBGPackingTabID = 0;
                DataSet dsPackRec = m_bllBGPackingTab.ShowOneBGPackRec("ContractCode = '" + modelPaidanTab.ContractCode + "'");

                if (dsPackRec.Tables.Count > 0 && dsPackRec.Tables[0].Rows.Count > 0)
                {
                    nSelectBGPackingTabID = Convert.ToInt32(dsPackRec.Tables[0].Rows[0]["BGPackingTabID"].ToString());
                }
                else
                {
                    nSelectBGPackingTabID = 0;
                }

                DataSet ds = m_bllBGPackGoodsMXTab.ShowGoodsMX("BGPackGoodsMXTab.BGPackingTabID = '" + nSelectBGPackingTabID + "'");
                DataTable dt = ds.Tables[0];
                //  if (Frm_Main.m_bCompleteVer == true)
                {
                    dt.Columns.Remove("单价");
                    dt.Columns.Remove("金额");
                    dt.Columns["打折单价"].ColumnName = "单价";
                    dt.Columns["打折金额"].ColumnName = "金额";
                }
                //else
                //{
                //    dt.Columns.Remove("打折单价");
                //    dt.Columns.Remove("打折金额");
                //}
                DataSet dsPackingTab = m_bllBGPackingTab.ShowOneBGPackRec("BGPackingTabID = '" + nSelectBGPackingTabID + "'");
                DataTable dt1 = dsPackingTab.Tables[0];
                if (dt1 != null)
                {
                    if (dt1.Rows.Count > 1)
                    {
                        MessageBox.Show("请选择不多于一条装箱单记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("装箱单记录不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        for (int v = 0; v < 1; v++)
                        {
                            string templetFile = templetFilePath + "发货单.xlt";
                            string outFile = "";
                            ExcelBase eB = new ExcelBase(templetFile, outFile);
                            ds = m_bllTaoDaPrinterNameTab.GetList("");
                            string strPrinterNameTemp = "";
                            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                            {
                                strPrinterNameTemp = ds.Tables[0].Rows[0]["TaoDaPrinterName"].ToString();
                            }
                            try
                            {
                                eB.OutGoodsSheet_DataTableToExcelAndPrint(dt, dt1, 14, 16, 1, "页", 3, strPrinterNameTemp);
                            }
                            catch (System.Exception ex)
                            {

                            }

                            eB.Close();
                        }
                    }
                }
                else
                {
                    MessageBox.Show("装箱单明细不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }

        private void buttonSendGoodsPreview_Click(object sender, EventArgs e)
        {
            if (m_nSelectlIndex < 0)
            {
                MessageBox.Show("请选择一行记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            UltraGridRow SelectUGR = ultraGrid1.Rows[m_nSelectlIndex];
            int nPaidanID = Convert.ToInt32(SelectUGR.Cells["PaidanRegisterTabID"].Value.ToString());

            DGBY.Model.PaidanRegisterTab modelPaidanTab = m_bllPaidanRegisterTab.GetModel(nPaidanID);
            if (modelPaidanTab == null)
                return;

            int nSelectBGPackingTabID = 0;
            DataSet dsPackRec = m_bllBGPackingTab.ShowOneBGPackRec("ContractCode = '" + modelPaidanTab.ContractCode + "'");

            if (dsPackRec.Tables.Count > 0 && dsPackRec.Tables[0].Rows.Count > 0)
            {
                nSelectBGPackingTabID = Convert.ToInt32(dsPackRec.Tables[0].Rows[0]["BGPackingTabID"].ToString());
            }
            else
            {
                nSelectBGPackingTabID = 0;
            }

            DataSet ds = m_bllBGPackGoodsMXTab.ShowGoodsMX("BGPackGoodsMXTab.BGPackingTabID = '" + nSelectBGPackingTabID + "'");
            DataTable dt = ds.Tables[0];
            //  if (Frm_Main.m_bCompleteVer == true)
            {
                dt.Columns.Remove("单价");
                dt.Columns.Remove("金额");
                dt.Columns["打折单价"].ColumnName = "单价";
                dt.Columns["打折金额"].ColumnName = "金额";
            }
            //else
            //{
            //    dt.Columns.Remove("打折单价");
            //    dt.Columns.Remove("打折金额");
            //}
            DataSet dsPackingTab = m_bllBGPackingTab.ShowOneBGPackRec("BGPackingTabID = '" + nSelectBGPackingTabID + "'");
            DataTable dt1 = dsPackingTab.Tables[0];
            if (dt1 != null)
            {
                if (dt1.Rows.Count > 1)
                {
                    MessageBox.Show("请选择不多于一条装箱单记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            else
            {
                MessageBox.Show("装箱单记录不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    for (int v = 0; v < 1; v++)
                    {
                        string templetFile = templetFilePath + "发货单.xlt";
                        string outFile = "";
                        ExcelBase eB = new ExcelBase(templetFile, outFile);
                        ds = m_bllTaoDaPrinterNameTab.GetList("");
                        string strPrinterNameTemp = "";
                        if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                        {
                            strPrinterNameTemp = ds.Tables[0].Rows[0]["TaoDaPrinterName"].ToString();
                        }
                        try
                        {
                            eB.OutGoodsSheet_DataTableToExcelAndPrintPreview(dt, dt1, 14, 16, 1, "页", 3);
                        }
                        catch (System.Exception ex)
                        {

                        }

                        //eB.Close();
                    }
                }
            }
            else
            {
                MessageBox.Show("装箱单明细不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void buttonInGoodsPrint_Click(object sender, EventArgs e)
        {
            if (m_dicSelectID2RowNo.Count == 0)
            {
                MessageBox.Show("未勾选记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            foreach (int nID in m_dicSelectID2RowNo.Keys)
            {
                UltraGridRow SelectUGR = ultraGrid1.Rows[m_dicSelectID2RowNo[nID]];
                int nPaidanID = Convert.ToInt32(SelectUGR.Cells["PaidanRegisterTabID"].Value.ToString());

                DGBY.Model.PaidanRegisterTab modelPaidanTab = m_bllPaidanRegisterTab.GetModel(nPaidanID);
                if (modelPaidanTab == null)
                    return;

                int nSelectBGPackingTabID = 0;
                DataSet dsPackRec = m_bllBGPackingTab.ShowOneBGPackRec("ContractCode = '" + modelPaidanTab.ContractCode + "'");

                if (dsPackRec.Tables.Count > 0 && dsPackRec.Tables[0].Rows.Count > 0)
                {
                    nSelectBGPackingTabID = Convert.ToInt32(dsPackRec.Tables[0].Rows[0]["BGPackingTabID"].ToString());
                }
                else
                {
                    nSelectBGPackingTabID = 0;
                }

                DataSet ds = m_bllBGPackGoodsMXTab.ShowGoodsMX("BGPackGoodsMXTab.BGPackingTabID = '" + nSelectBGPackingTabID + "'");
                DataTable dt = ds.Tables[0];
                //  if (Frm_Main.m_bCompleteVer == true)
                {
                    dt.Columns.Remove("单价");
                    dt.Columns.Remove("金额");
                    dt.Columns["打折单价"].ColumnName = "单价";
                    dt.Columns["打折金额"].ColumnName = "金额";
                }
                //else
                //{
                //    dt.Columns.Remove("打折单价");
                //    dt.Columns.Remove("打折金额");
                //}
                DataSet m_ds = m_bllBGPackingTab.ShowOneBGPackRec("BGPackingTabID = '" + nSelectBGPackingTabID + "'");
                DataTable dt1 = m_ds.Tables[0];
                if (dt1 != null)
                {
                    if (dt1.Rows.Count > 1)
                    {
                        MessageBox.Show("请选择不多于一条装箱单记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("装箱单记录不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        string templetFile = templetFilePath + "进货单.xlt";
                        string outFile = "";
                        ExcelBase eB = new ExcelBase(templetFile, outFile);
                        ds = m_bllTaoDaPrinterNameTab.GetList("");
                        string strPrinterNameTemp = "";
                        if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                        {
                            strPrinterNameTemp = ds.Tables[0].Rows[0]["TaoDaPrinterName"].ToString();
                        }
                        try
                        {
                            eB.InGoodsSheet_DataTableToExcelAndPrint(dt, dt1, 14, 16, 1, "页", "", strPrinterNameTemp);
                        }
                        catch (System.Exception ex)
                        {

                        }

                        eB.Close();
                    }
                }
                else
                {
                    MessageBox.Show("装箱单明细不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }

        private void buttonInGoodsPrintPreview_Click(object sender, EventArgs e)
        {
           if (m_nSelectlIndex < 0)
            {
                MessageBox.Show("请选择一行记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            UltraGridRow SelectUGR = ultraGrid1.Rows[m_nSelectlIndex];
            int nPaidanID = Convert.ToInt32(SelectUGR.Cells["PaidanRegisterTabID"].Value.ToString());

            DGBY.Model.PaidanRegisterTab modelPaidanTab = m_bllPaidanRegisterTab.GetModel(nPaidanID);
            if (modelPaidanTab == null)
                return;

            int nSelectBGPackingTabID = 0;
            DataSet dsPackRec = m_bllBGPackingTab.ShowOneBGPackRec("ContractCode = '" + modelPaidanTab.ContractCode + "'");

            if (dsPackRec.Tables.Count > 0 && dsPackRec.Tables[0].Rows.Count > 0)
            {
                nSelectBGPackingTabID = Convert.ToInt32(dsPackRec.Tables[0].Rows[0]["BGPackingTabID"].ToString());
            }
            else
            {
                nSelectBGPackingTabID = 0;
            }

            DataSet ds = m_bllBGPackGoodsMXTab.ShowGoodsMX("BGPackGoodsMXTab.BGPackingTabID = '" + nSelectBGPackingTabID + "'");
            DataTable dt = ds.Tables[0];
            //  if (Frm_Main.m_bCompleteVer == true)
            {
                dt.Columns.Remove("单价");
                dt.Columns.Remove("金额");
                dt.Columns["打折单价"].ColumnName = "单价";
                dt.Columns["打折金额"].ColumnName = "金额";
            }
            //else
            //{
            //    dt.Columns.Remove("打折单价");
            //    dt.Columns.Remove("打折金额");
            //}
            DataSet m_ds = m_bllBGPackingTab.ShowOneBGPackRec("BGPackingTabID = '" + nSelectBGPackingTabID + "'");
            DataTable dt1 = m_ds.Tables[0];
            if (dt1 != null)
            {
                if (dt1.Rows.Count > 1)
                {
                    MessageBox.Show("请选择不多于一条装箱单记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            else
            {
                MessageBox.Show("装箱单记录不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    string templetFile = templetFilePath + "进货单.xlt";
                    string outFile = "";
                    ExcelBase eB = new ExcelBase(templetFile, outFile);
                    ds = m_bllTaoDaPrinterNameTab.GetList("");
                    string strPrinterNameTemp = "";
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        strPrinterNameTemp = ds.Tables[0].Rows[0]["TaoDaPrinterName"].ToString();
                    }
                    try
                    {
                        eB.InGoodsSheet_DataTableToExcelAndPrintPreview(dt, dt1, 14, 16, 1, "页", "");
                    }
                    catch (System.Exception ex)
                    {

                    }

                   // eB.Close();
                }
            }
            else
            {
                MessageBox.Show("装箱单明细不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void buttonExportToExcel_Click(object sender, EventArgs e)
        {
            DataTable dt = (DataTable)ultraGrid1.DataSource;

            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.Filter = "Excel文件(*.xls)|*.xls";
                    string outFile = "";

                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        outFile = sfd.FileName;
                    }
                    else
                    {
                        return;
                    }

                    ultraGrid1.DisplayLayout.Bands[0].Columns["全选"].Hidden = true;
                    ultraGridExcelExporter1.Export(ultraGrid1, outFile);
                }
            }
        }

        private void ultraGridExcelExporter1_EndExport(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.EndExportEventArgs e)
        {
            ultraGrid1.DisplayLayout.Bands[0].Columns["全选"].Hidden = false;
        }

        private void buttonSort_Click(object sender, EventArgs e)
        {
            List<object> lstO = this.ultraGrid1.DisplayLayout.Bands[0].ColumnFilters.All.ToList();

            string strColumnName;
            string strColumnValue;
            string strTableColumnValue;
            StringBuilder strSql = new StringBuilder();

            foreach (object o in lstO)
            {
                ColumnFilter cf = (ColumnFilter)o;
                strColumnName = cf.Column.Key;
                strColumnValue = cf.FilterConditions.Count > 0 ? ((FilterCondition)cf.FilterConditions.All[0]).CompareValue.ToString() : "";

                if (!string.IsNullOrEmpty(strColumnValue))
                {
                    strTableColumnValue = GetTableColumnValue(strColumnName);
                    if (string.IsNullOrEmpty(strTableColumnValue.ToString()))
                        continue;

                    if (string.IsNullOrEmpty(strSql.ToString()))
                    {
                        strSql = strSql.Append(" " + strTableColumnValue + "='" + strColumnValue + "'");
                    }
                    else
                    {
                        strSql = strSql.Append(" and " + strTableColumnValue + "='" + strColumnValue + "'");
                    }
                }
            }

            ShowAllRecordSort(strSql.ToString());
        }

        private string GetTableColumnValue(string strColumnName)
        {
            string strTableColumnValue = "";

            if (strColumnName == "业务员")
            {
                strTableColumnValue = "T_ACL_User.Name";
            }
            else if (strColumnName == "申报年月")
            {
                strTableColumnValue = "case when year(HxdNoTab.SBDate) = 1900 then '' else CONVERT(varchar(6), HxdNoTab.SBDate, 112) end";
            }
            else if (strColumnName == "公司")
            {
                strTableColumnValue = "BYCompanyTab.CompanyNameJX";
            }
            else if (strColumnName == "部门")
            {
                strTableColumnValue = "BYDepartTab.DepartName";
            }
            else if (strColumnName == "订单号")
            {
                strTableColumnValue = "PaidanRegisterTab.DingDanCode";
            }
            else if (strColumnName == "工厂简称")
            {
                strTableColumnValue = "FactoryDataTab.FactoryNameJX";
            }
            else if (strColumnName == "合同编号")
            {
                strTableColumnValue = "PaidanRegisterTab.ContractCode";
            }
            else if (strColumnName == "柜号")
            {
                strTableColumnValue = "dbo.f_CargoBoxNoCollectFun(PaidanRegisterTab.PaidanRegisterTabID)";
            }
            else if (strColumnName == "申报日期")
            {
                strTableColumnValue = "case when year(HxdNoTab.SBDate) = 1900 then '' else HxdNoTab.SBDate end";
            }
            else if (strColumnName == "报关金额")
            {
                strTableColumnValue = "BGJinETab.bgMoneyCount";
            }
            else if (strColumnName == "币制")
            {
                strTableColumnValue = "BiZhiTab.BiZhiName";
            }
            else if (strColumnName == "目的国家")
            {
                strTableColumnValue = "MDCountryTab.MDCountryName";
            }
            else if (strColumnName == "柜数")
            {
                strTableColumnValue = "GuiTab.GuiCount";
            }
            else if (strColumnName == "总毛重")
            {
                strTableColumnValue = "BGJinETab.sumMz";
            }
            else if (strColumnName == "总净重")
            {
                strTableColumnValue = "BGJinETab.sumJz";
            }
            
            return strTableColumnValue;
        }
    }
}
